/**
 * 封装分页组件
 */
'use strict';
import React, {
    Component
} from 'react'
import {
    Link,
    hashHistory
} from 'react-router'

import {
    Pagination
} from 'react-bootstrap'

export default class bootstrapPage extends Component {
    constructor(props) {
        super(props);
    }
    render() {
        let { nextPage, prePage, pageNum, pages } = this.props;
        let items = [];
        if(pages == 0 ){
            items.push(<Pagination.Item active >{0}</Pagination.Item>)
        }else if(pages <= 10){
            for(let i = 1;i <= pages ;i++) {
                if (i == pageNum) {
                    items.push(<Pagination.Item active >{i}</Pagination.Item>)
                } else {
                    items.push(<Pagination.Item >{i}</Pagination.Item>)
                }
            }
        }else if(pages > 10 && pageNum < 6) {
            items.push(<Pagination.Item >{1}</Pagination.Item>);
            for(let i = 1;i <= 5 ;i++){
                if(i == pageNum){
                    items.push(<Pagination.Item active >{i}</Pagination.Item>)
                }else{
                    items.push(<Pagination.Item >{i}</Pagination.Item>)
                }
            }
            items.push(<Pagination.Ellipsis disabled />);
            items.push(<Pagination.Item>{pages}</Pagination.Item>)

        }else if(pages > 10 && pages-pageNum < 6) {
            items.push(<Pagination.Item >{1}</Pagination.Item>);
            items.push(<Pagination.Ellipsis disabled />);
            for(let i = pageNum-5;i <= pages ;i++){
                if(i == pageNum){
                    items.push(<Pagination.Item active >{i}</Pagination.Item>)
                }else{
                    items.push(<Pagination.Item >{i}</Pagination.Item>)
                }
            }
            items.push(<Pagination.Item>{pages}</Pagination.Item>)
        }else if(pages > 10 && pageNum > 6) {
            items.push(<Pagination.Item >{1}</Pagination.Item>);
            items.push(<Pagination.Ellipsis disabled />);
            for(let i = pageNum-2;i <= pageNum+2 ;i++){
                if(i == pageNum){
                    items.push(<Pagination.Item active >{i}</Pagination.Item>)
                }else{
                    items.push(<Pagination.Item >{i}</Pagination.Item>)
                }
            }
            items.push(<Pagination.Ellipsis disabled />);
            items.push(<Pagination.Item>{pages}</Pagination.Item>)
        }
        return (
            <Pagination style={{ float:'right'}}>
                {
                    prePage==0?
                        [
                            <Pagination.First disabled />,
                            <Pagination.Prev disabled />
                        ]
                     :
                        [
                            <Pagination.First />,
                            <Pagination.Prev />
                        ]
                }
                {items}
                {
                    nextPage==0?
                        [
                            <Pagination.Next disabled />,
                            <Pagination.Last disabled />
                        ]
                        :
                        [
                            <Pagination.Next />,
                            <Pagination.Last />
                        ]
                }

            </Pagination>
        )
    }
}
